home *** CD-ROM | disk | FTP | other *** search
- Path: gate.itron.com!usenet
- From: ronald.ten-hove@itron.com (Ron Ten-Hove)
- Newsgroups: comp.lang.c,comp.lang.c++,comp.os.ms-windows.programmer.misc,comp.os.msdos.programmer,comp.programming,comp.windows.ms.programmer
- Subject: Re: Date Arithmetic
- Date: 20 Feb 1996 00:12:45 GMT
- Organization: Itron Inc.
- Message-ID: <4gb3lt$7vf@gate.itron.com>
- References: <4g19kp$640@tracy.protocom.com>
- Reply-To: ronald.ten-hove@itron.com (Ron Ten-Hove)
- NNTP-Posting-Host: itron12-23.itron.com
- X-Newsreader: IBM NewsReader/2 v1.02
-
- In <4g19kp$640@tracy.protocom.com>, "Michael J. Karas" <mkaras@pclink.com> writes:
- >I am working on an algorithm for a laser marking machine that writes
- >expiration delays on to food product boxes. The algorithm needs to
- >be able to add NNN days to todays date in the fastest manner possible
- >without using any floating point arithmetic. I could use help from anyone
- >that has C code for doing this. It would be nice if the solution took the
- >leap year problem in to account including the special case of the year
- >2000. Thanks in advance to anyone who could share their knowledge on this
- >subject.
-
- What you need is a two-way conversion process:
-
- calendar-date -> Julian-date
- Jullian-date -> calendar-date
-
- You can convert the current date to Julian, add NNN days, and convert
- back to normal calendar date.
-
- Many libraries include Julian date calculations. If you are
- using C++, for example, the Rogue Wave tools.h++ library has an excellent
- class named RWDate that will convert between Julian and calendar
- dates very easily.
-
- There are *many* unix shell scripts that show the basic algorithms
- used for such conversions. I believe the ACM has documented them
- in their ``Collected Algorithms'' books.
-
- -Ron
-
-
-